const fs = require('mz/fs')
var md = require('markdown-it')({
  html: true,
  linkify: true,
  typography: true
})

function generatorHtml(body) {

  const cssUrl = 'https://cdn.bootcss.com/highlight.js/9.12.0/styles/atom-one-light.min.css'
  let head = `<link rel="stylesheet" href="${cssUrl}">\
  <script src="https://cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js"></script>\
  <script>hljs.initHighlightingOnLoad();</script>`
  return `<html><head>${head}</head><body>${body}</body</html>`
}

let fn_docs = async (ctx, next) => {
  console.log("进入。。。。。。。。。");
  let datas = await fs.readFile(__dirname + '/../docs/mysql.md')
  ctx.response.type = 'text/html';
  let body = md.render(datas.toString())
  ctx.response.body = generatorHtml(body)
}

module.exports = {
  "GET /mysql": fn_docs
}
